package steak.xteamy.client.mixin;

import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import steak.xteamy.KillerGroup;
import steak.xteamy.Network.Packets;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin {

    @Unique LivingEntity self = (LivingEntity) (Object) this;

    @Inject(method = "isClimbing", at = @At("HEAD"), cancellable = true)
    private void onIsClimbing(CallbackInfoReturnable<Boolean> cir) {

        if (self instanceof PlayerEntity player) {
            //攀爬能力
            if (player.hasStatusEffect(KillerGroup.CLIMBABLE) && player.horizontalCollision) {
                cir.setReturnValue(true);
            }

            //直升机能力
            if (player.hasStatusEffect(KillerGroup.HELICOPTER_MODE)) {
                cir.setReturnValue(true);
                if (player.horizontalCollision && player.getWorld().isClient()) {

                    self.removeStatusEffect(KillerGroup.HELICOPTER_MODE);
                    ClientPlayNetworking.send(new Packets.HorizontalCollision(true));
                }
            }
        }
    }
}
